﻿using System;

namespace VIES.Tests.Generic
{
    using VIES;

    /// <summary>
    /// Client application for generic tests
    /// </summary>
    /// <remarks>Philipp Schosteritsch, SCHOSTE.COM</remarks>
    class TestClient
    {
        /// <summary>
        /// Entry point of the application
        /// </summary>
        /// <param name="args">Command line arguments. A VAT number to look up is expected</param>
        /// <returns>0 on success, 1 on error</returns>
        public static int Main(string[] args)
        {
            if((args == null) || (args.Length < 1)) return 0;

            try
            {
                var vatNumber = args[0];
                var vatInfomration = WebService.Instance.Verify(vatNumber);

                if (vatInfomration.Valid) PrintInformation(vatInfomration);

                if (!vatInfomration.Valid) Console.WriteLine(Resources.SubmittedInvalidVat);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(Resources.VerifyException, args[0]);
                Console.Error.WriteLine(ex.Message);
                return 1;
            }

            return 0;
        }

        /// <summary>
        /// Prints information of a VATInformation object returned
        /// by the VIES web service
        /// </summary>
        /// <param name="info">The reference to the object to display</param>
        public static void PrintInformation(VATInformation info)
        {
            Console.WriteLine(Resources.VatIsKeyFor, info.VATNumber);
            Console.WriteLine(Resources.VatInfoName, info.Name);
            Console.WriteLine(Resources.VatInfoAddress, info.Address);            
        }
    }
}
